<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/pages/safeai/jsp/common/taglibs.jsp"%>
<html>
<head>
<title>addPw_members</title>
<%@ include file="/pages/safeai/jsp/common/meta.jsp"%>
<style type="text/css">
<!--
.STYLE1 {
	color: #FF0000
}
-->
</style>
<link href="${ctx}/css/safeai/together.css" rel="stylesheet" type="text/css">
<script type='text/javascript' src='${ctx}/js/Ajax.js'></script>
<script type='text/javascript' src='${ctx}/dwr/engine.js'></script>
<script type='text/javascript' src='${ctx}/dwr/util.js'></script>
</head>

<body>
<html:form method="post" action="/pw_members/pw_membersManage">
	<table width="450px" align="center"> 
		<input type="hidden" name="pw_members.uidStr" value="${hpw_members.uidStr}"/>
			<input type="hidden" name="hpw_members.username" value="${hpw_members.username}"/>
			<input type="hidden" name="hpw_members.realName" value="${hpw_members.realName}"/>
			<input type="hidden" name="hpw_members.email" value="${hpw_members.email}"/>
			<input type="hidden" name="hpw_members.mobile" value="${hpw_members.mobile}"/>
			<input type="hidden" name="hpw_members.vip" value="${hpw_members.vip}"/>
			<input type="hidden" name="hpw_members.redate"value="${hpw_members.redate}"/>
            <input type="hidden" name="hpw_members.brandId"value="${hpw_members.brandId}"/>
		<logic:notPresent name="pw_members">
			<tr>
				<th colspan="2" height="25px">新增会员</th>
			</tr>
			<input type="hidden" id="meth" name="method" value="addPw_members" />
			<tr>
			<td class="td_01" width="100px">用户名：</td>
			<td class="td_04"><input type="text" id="username"
				name="pw_members.username" value="${pw_members.username}${hpw_members.username }" maxlength="12"/><span
				class="STYLE1">*</span></td>
			</tr>
			<tr>
				<td class="td_01">密码：</td>
				<td class="td_04"><input type="password" maxlength="16" id="password"
					name="pw_members.password"/><span
					class="STYLE1">*</span></td>
				<input type="hidden" id="pTag" name="passwordTag" value="${pw_members.password}" />
			</tr>
			<tr>
				<td class="td_01">确认密码：</td>
				<td class="td_04"><input type="password" maxlength="16" id="pword"
					name="pw_members.password"/><span
					class="STYLE1">*</span></td>
				<input type="hidden" id="pTag" name="passwordTag" value="${pw_members.password}" />
			</tr>
		</logic:notPresent>
		<logic:present name="pw_members">
			<tr>
				<th colspan="2" height="25px">修改会员</th>
			</tr>
			<input type="hidden" id="meth" name="method" value="updatePw_members" />
			<input type="hidden" name="pw_members.uid" value="${pw_members.uid }" />
			<input type="hidden"  id="username" name="pw_members.username" value="${pw_members.username }" />
			<tr>
			<td class="td_01" width="100px">用户名：</td>
			<td class="td_04">${pw_members.username}<span
				class="STYLE1">*</span></td>
			</tr>
			<tr>
				<td class="td_01">密码：</td>
				<td class="td_04"><input type="password" maxlength="16" id="password"
					name="pw_members.password"/><span
					class="STYLE1">*</span>如不输入密码,则保持原密码不变</td>
				<input type="hidden" id="pTag" name="passwordTag" value="${pw_members.password}" />
			</tr>
			<tr>
				<td class="td_01">确认修改密码：</td>
				<td class="td_04"><input type="password" maxlength="16" id="pword"
					name="pw_members.password"/><span
					class="STYLE1">*</span></td>
				<input type="hidden" id="pTag" name="passwordTag" value="${pw_members.password}" />
			</tr>
		</logic:present> 
		<tr>
			<td class="td_01">真实姓名：</td>
			<td class="td_04"><input type="text" maxlength="10" name="pw_members.realName"
				value="${pw_members.realName}${hpw_members.realName }" /></td>
		</tr>
		<tr>
			<td class="td_01">email：</td>
			<td class="td_04"><input type="text" maxlength="60" id="email" name="pw_members.email"
				value="${pw_members.email}${hpw_members.email }" /></td>
		</tr>

		<tr>
			<td class="td_01">手机：</td>
			<td class="td_04"><input type="text" maxlength="35" id="mobile" name="pw_members.mobile"
				value="${pw_members.mobile}${hpw_members.mobile }" /></td>
		</tr>
		
		<tr>
			<td class="td_01">电话：</td>
			<td class="td_04"><input type="text" maxlength="50" id="phone" name="pw_members.phone"
				value="${pw_members.phone}${hpw_members.phone }" /></td>
		</tr>
		
		<tr>
			<td class="td_01">Vip卡号：</td>
			<td class="td_04"><input type="text" maxlength="12" id="vip" name="pw_members.vip"
				value="${pw_members.vip}${hpw_members.vip }" /></td>
		</tr>
		<tr>
			<td class="td_01">性别：</td>
			<td class="td_04">
			<logic:notPresent name="pw_members">
				<select name="pw_members.gender">
					<option value="1">男</option>
					<option value="2">女</option>
				</select>
			</logic:notPresent>
			<logic:present name="pw_members">
				<select name="pw_members.gender">
					<logic:equal name="pw_members" property="gender" value="1">
						<option value="1" selected>男</option>
						<option value="2">女</option>
					</logic:equal>
					<logic:notEqual name="pw_members" property="gender" value="1">
				    	<option value="1">男</option>
						<option value="2" selected>女</option>
				    </logic:notEqual> 
				</select>
			</logic:present> 
			</td>
		</tr>
		<tr>
			<td class="td_01">邮编：</td>
			<td class="td_04"><input type="text"  maxlength="20"  id="postCode" name="pw_members.postCode" value="${pw_members.postCode}${hpw_members.postCode }"/></td>
		</tr>
		<tr>
			<td class="td_01">传真：</td>
			<td class="td_04"><input type="text" name="pw_members.fax"  maxlength="62" value="${pw_members.fax}${hpw_members.fax }" /></td>
		</tr>
		<tr>
			<td class="td_01">地址：</td>
			<td class="td_04"><input type="text" name="pw_members.address"  maxlength="255" value="${pw_members.address}${hpw_members.address }" /></td>
		</tr>
		
		<tr>
			<td class="td_01">城市：</td><input type="hidden" id="provinceValue" value="${pw_members.province}${hpw_members.province }" /><input type="hidden" id="cityValue" value="${pw_members.rcity}${hpw_members.rcity }" /><input type="hidden" id="villageValue" value="${pw_members.town}${hpw_members.town }" />
			<td class="td_04">省：<select name="pw_members.province" id="provinces"></select><br><br>市：<select name="pw_members.rcity" id="citys"></select><br><br>区：<select name="pw_members.town" id="villages"></select></td>
		</tr>
		<tr>
			<td colspan="2" align="center"><span style="font-family:'宋体'; font-size:12px; color:#FF0000">${pwmemMsg}</span></td>
		</tr>
		<tr>
			<td colspan="2" align="center"><input name="submit"
				type="submit" class="btn" value="提交" onclick="return sub();">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="button" name="return" class="btn" value="返回"
				onmousedown="javascript:history.go(-1);" /></td>
		</tr>
	</table>
</html:form>
</body>
</html>
<script language="javascript"> 
    window.onload=function(){//onload start    
    //************************城市级联开始**********************************
       //省
       var provinces=document.getElementById("provinces");
       //市
       var citys=document.getElementById("citys");
       //区
       var villages=document.getElementById("villages");
       
       getProvinces();
       getCitys();
       getVillages();
       
       provinces.onchange=function(){
           getCitys();
           getVillages(); 
          
       }
       citys.onchange=function(){
           getVillages();
           
       }
       
    var v1 = window.document.getElementById("provinceValue").value;
    var v2 = window.document.getElementById("cityValue").value;
    var v3 = window.document.getElementById("villageValue").value;
       
 	if(v1 != null && v1 != "" && v2 != null && v2 != "" && v3 != null && v3 != ""){
		var provinceOptions = window.document.getElementById("provinces");
		var cityOptions = window.document.getElementById("citys");
		var villageOptions = window.document.getElementById("villages");
		
		var itemCount1 = provinceOptions.options.length; 
		
		for (var i=0;i <itemCount1;i++){ 
			if (provinceOptions.options[i].value == v1){	       
		        provinceOptions.options[i].selected = true;
		      } 
	    } 
	    
	    provinceOptions.onchange();
	    var itemCount = cityOptions.options.length;
		
	   
		for (var j=0;j <itemCount;j++){  
			if (cityOptions.options[j].value == v2){	        
		        cityOptions.options[j].selected = true;
		    } 
	    } 
	    
	    cityOptions.onchange();
	    var itemCount2 = villageOptions.options.length;
	    
		for (var z=0;z <itemCount2;z++){ 
			if (villageOptions.options[z].value == v3) {	       
		        villageOptions.options[z].selected = true;
		    } 
	    }
	    
	   
    }
       
       
    }//onload end
    function getProvinces(){
        var ajax=new Ajax();
        ajax.ajaxRequest("${ctx}/order/cityOreder.do","method=getAllProvince","get",backProvince);
    }
    
    function backProvince(str){
        var list=str.split(",");
        DWRUtil.removeAllOptions("provinces");
	    DWRUtil.addOptions("provinces", list);
    }
    
    function getCitys(){
        var ajax=new Ajax();
        var provinces=document.getElementById("provinces");
        var provinceName=provinces.options[provinces.selectedIndex].value;
        ajax.ajaxRequest("${ctx}/order/cityOreder.do","method=getCitys&provinceName="+encodeURI(provinceName),'get',backCity);
    }
    
    function backCity(str){
        var list=str.split(",");
        DWRUtil.removeAllOptions("citys");
	    DWRUtil.addOptions("citys", list);
    }
    
    function getVillages(){
        var ajax=new Ajax();
        var provinces=document.getElementById("provinces");
        var citys=document.getElementById("citys");
        var provinceName=provinces.options[provinces.selectedIndex].value;
        var cityName=citys.options[citys.selectedIndex].value;
        ajax.ajaxRequest("${ctx}/order/cityOreder.do","method=getVillages&provinceName="+encodeURI(provinceName)+"&cityName="+encodeURI(cityName),'get',backVillage);
    }
    
    function backVillage(str){
        var list=str.split(",");
        DWRUtil.removeAllOptions("villages");
	    DWRUtil.addOptions("villages", list);
    }
    
    //************************城市级联结束**********************************
        function sub(){
        	 var meth = document.getElementById("meth").value;
             var username = document.getElementById("username").value;
             var passwd = document.getElementById("password").value;
             var passwprd = document.getElementById("pTag").value; 
             var pword = document.getElementById("pword").value;
             var postCode = document.getElementById("postCode").value;
             var email = document.getElementById("email").value;
             var mobile = document.getElementById("mobile").value;
             var phone = document.getElementById("phone").value;          
             if(username.indexOf(" ")!=-1){
			 	alert("用户名中不能包含空格!");
			 	return false;
			 }   
			  if(passwd.indexOf(" ")!=-1){
			 	alert("密码中不能包含空格!");
			 	return false;
			 }                             
             if(meth != "addPw_members"){
	             if(passwd == null || passwd == ""){
	             	document.getElementById("password").value = passwprd;
	             	document.getElementById("pword").value = passwprd;
	                //alert("请输入密码!");
	                //document.getElementById("password").focus();
	                //return false;
	             }  
             }else{
                 if(username == null || username == ""){
	                alert("请输入帐号!");
	                document.getElementById("username").focus();
	                return false;
	             }
	             
	             if(passwd == null || passwd == ""){
	             	document.getElementById("password").value = passwprd;
	                alert("请输入密码!");
	                document.getElementById("password").focus();
	                return false;
	             }
             }
             //	邮箱验证
            if(email!=null && email!=""){
				var pattern =/^[a-zA-Z0-9_\-.]{1,}@[a-zA-Z0-9_\-]{1,}\.[a-zA-Z0-9_\-.]{1,}$/;
				if(!pattern.exec(email)){
					alert("请输入正确的邮箱地址!");
					return false;
				}
				if(email.length>60){
					alert("邮箱的最大长度为60个字符!");
					return false;
				}
			}		
		//if(mobile!=""){
		//	if(mobile.search(/^((\(\d{3}\))|(\d{3}\-))?13[0-9]\d{8}|15[89]\d{8}/) == -1){
		//		alert("输入的手机格式错误");
		//		document.getElementById("mobile").focus();
		//		return false;
		//	}
		//}
		//	手机验证
		if(mobile == null || mobile == ""){
			document.getElementById("mobile").focus();
			alert("请输入您的手机号码!");
			return false;
		}else{
			if(mobile.length!=11){
				alert("手机号码长度不对！");
				return false;
			}
		}
		if(phone!=null&&phone!=""){
			var strphone;
			if(phone.indexOf("，")==-1){
				strphone=phone.split(",");
			}else{
				strphone=phone.split("，");
			}
			for(i=0;i<strphone.length;i++){
				if(strphone[i].search(/^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/) == -1){
					alert("输入的电话格式错误");
					document.getElementById("phone").focus();
					return false;
				}
			}	
		}

		if(postCode!=null && postCode!=""){
			if(postCode.search("^-?\\d+$")!=0){
				alert("输入的邮编格式错误");
				document.getElementById("postCode").focus();
				return false;
			}  
			if(postCode.length!=6){
				document.getElementById("postCode").focus();
				alert("输入的邮编位数不正确!");
				return false;
			}
		}
              if(passwd!=pword){
	             	alert("两次输入的密码不一致,请输重新输入确认密码!");
	             	return false;
	          }  
	          var provinces = document.getElementById("provinces").value;
				if(provinces=="请选择"){
					alert("请选择省份");
					return false;
				}
				var citys = document.getElementById("citys").value;
				if(citys=="请选择"){
					alert("请选择城市");
					return false;
				}
				var villages = document.getElementById("villages").value;
				if(villages=="请选择"){
					alert("请选择区");
					return false;
				}
        }  
    </script>